package org.jeecg.modules.demo.roomapartdistribute.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.demo.applyinfo.entity.ZnzfDetermineApart;
import org.jeecg.modules.demo.roomapartdistribute.entity.ZnzfCheckApart;
import org.jeecg.modules.demo.roomapartdistribute.mapper.ZnzfCheckApartMapper;
import org.jeecg.modules.demo.roomapartdistribute.service.IZnzfCheckApartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 核定单位
 * @Author: jeecg-boot
 * @Date:   2022-03-21
 * @Version: V1.0
 */
@Service
public class ZnzfCheckApartServiceImpl extends ServiceImpl<ZnzfCheckApartMapper, ZnzfCheckApart> implements IZnzfCheckApartService {

    @Resource
    private ZnzfCheckApartMapper znzfCheckApartMapper;

    @Override
    public List<ZnzfCheckApart> searchsByZnzfRoomApartDistributeId(String radId) {
        LambdaQueryWrapper<ZnzfCheckApart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZnzfCheckApart::getRoomApartDistributeId, radId);
        return znzfCheckApartMapper.selectList(queryWrapper);
    }

    @Override
    public ZnzfCheckApart searchByZnzfRoomApartDistributeIdAndApartId(String radId, String apartId) {
        LambdaQueryWrapper<ZnzfCheckApart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZnzfCheckApart::getRoomApartDistributeId, radId);
        queryWrapper.eq(ZnzfCheckApart::getApartId, apartId);
        return znzfCheckApartMapper.selectOne(queryWrapper);
    }

    /**
     * 查询核定部门的审核状态
     *
     * @param id
     * @return
     */
    @Override
    public String checkState(String id) {
        return znzfCheckApartMapper.selectById(id).getState();
    }

    /**
     * 驳回或通过,修改状态和备注
     *
     * @param id
     * @param note
     * @param state
     * @return
     */
    @Override
    public int passOrDeny(String id, String note, String state) {
        ZnzfCheckApart checkApart = new ZnzfCheckApart();
        checkApart.setId(id);
        checkApart.setNote(note);
        checkApart.setState(state);
        return znzfCheckApartMapper.updateById(checkApart);
    }

    @Override
    public List<ZnzfCheckApart> findByRadId(String radId) {
        LambdaQueryWrapper<ZnzfCheckApart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZnzfCheckApart::getRoomApartDistributeId, radId);
        List<ZnzfCheckApart> znzfCheckApartList = znzfCheckApartMapper.selectList(queryWrapper);
        return znzfCheckApartList;
    }
}
